﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace AssetLoad
{
    public class AudioLoader : LoaderBase
    {
        public override string GetPrefix()
        {
            return @"audio/";
        }

        public IEnumerator LoadAudio(string audioName, LoadCompleteNotify callback) {
#if !FIX_RESOURCE
            string abName = GetPrefix() + audioName;
            abName = abName.ToLower();
            AssetBundleManager.Instance.LoadAssetBundle(abName);
            while (!AssetBundleManager.Instance.IsLoadedAssetBundle(abName)) {
                yield return null;
            }
            if (callback != null) {
                callback();
            }
#else
            ResourceManager.Instance.LoadResource(GetPrefix() + audioName);
            yield return 0;
            if (callback != null) {
                callback();
            }
#endif
        }

        public void UnloadAudio(string audioName) {
#if !FIX_RESOURCE
            string abName = GetPrefix() + audioName;
            abName = abName.ToLower();
            AssetBundleManager.Instance.UnloadAssetBundle(abName);
#else
            ResourceManager.Instance.UnloadResource(GetPrefix() + audioName);
#endif
        }

        public AudioClip GetAudioClip(string audioName) {
#if !FIX_RESOURCE
            string abName = GetPrefix() + audioName;
            abName = abName.ToLower();
            return AssetBundleManager.Instance.GetAssetFromBundle(abName, audioName, typeof(AudioClip)) as AudioClip;
#else
            return ResourceManager.Instance.GetResource(GetPrefix() + audioName) as AudioClip;
#endif
        }
    }
}
